package internal

import (
	"log/slog"
	"sync"
	"sync/atomic"
)

var (
	loggerInstance = atomic.Pointer[slog.Logger]{}
	loggerOnce     sync.Once
)

// GetLogger 获取全局日志实例, 默认使用 slog.Default()
func GetLogger() *slog.Logger {
	if v := loggerInstance.Load(); v != nil {
		return v
	}
	loggerOnce.Do(func() {
		loggerInstance.Store(slog.Default())
	})
	return loggerInstance.Load()
}
func SetLogger(log *slog.Logger) {
	if log != nil {
		loggerInstance.Store(log)
	}
}
